package com.zang.blogz.config;

import com.zang.blogz.handler.ZVerifyWebSocketHandler;
import com.zang.blogz.intercept.ZVerifyWebSocketInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;

/**
 * @Author: ZVerify
 * @Description: TODO WebSocket相关配置
 * @DateTime: 2022/9/6 14:21
 **/
@Configuration
@EnableWebSocket
public class ZVerifyWebSocketConfig implements WebSocketConfigurer {

    // 注册 WebSocket 处理器
    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry webSocketHandlerRegistry) {
        webSocketHandlerRegistry
                // WebSocket 连接处理器
                .addHandler(new ZVerifyWebSocketHandler(), "/ws-connect")
                // WebSocket 拦截器
                .addInterceptors(new ZVerifyWebSocketInterceptor())
                // 允许跨域
                .setAllowedOrigins("*");
    }

}
